package com.hbnu.array;

import java.util.Scanner;

public class ArrayDemo02 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        // 创建数组
        int[] array = new int[5];

        // 输入数组元素
        System.out.println("请输入数组元素:");
        for (int i = 0; i < 5; i++) {
            array[i] = scanner.nextInt();
        }
        //排序
        int temp=0;
        for (int i = 0; i < array.length-1 ; i++) {
            for (int j = 0; j < array.length-1-i ; j++) {
                if (array[j]>array[j+1])
                {
                    temp=array[j];
                    array[j]=array[j+1];
                    array[j+1]=temp;
                }
            }
        }

        // 打印数组
            System.out.print("从小到大为: ");
            for (int i = 0; i < 5; i++) {
                System.out.print(array[i] + " ");
            }

    }
}
